package main

import (
	
	"github.com/afex/hystrix-go/hystrix"
	"math/rand"
	"gowork/goKit/consulClientKit/util"
	"time"
	"fmt"
)

func main() {

	//	熔断、降级
	rand.Seed(time.Now().UnixNano())
	configHystrix := hystrix.CommandConfig{
		Timeout: 2000,
		MaxConcurrentRequests: 5,
		RequestVolumeThreshold: 3,
		ErrorPercentThreshold: 20,
		SleepWindow: int(time.Second*100),
	}
	hystrix.ConfigureCommand("getUser", configHystrix)
	err := hystrix.Do("getUser", func() error{
		res, err := util.GetUtil()
		fmt.Println(res)
		return err
	}, func(e error) error{
		fmt.Println("服务降级")
		return e
	})
	if err != nil{
		fmt.Println(err)
	}
}